"""
FastAPI 主应用文件
"""
import uvicorn
import os
import initServer
from utils.loggingConfig import get_logger

app = initServer.getApp()

# 健康检查
@app.get("/")
async def health():
    logger = get_logger('')
    logger.info('health')
    return {"message": "health"}

# 显示环境变量
@app.get("/env")
async def envFunc():
    """显示环境变量"""
    logger = get_logger('')
    envdict = dict(os.environ)
    for k , v in envdict.items():
        logger.info(f'{k} -> {v}')
    return {"message": "欢迎使用 FastAPI 应用"}


if __name__ == "__main__":
    # 从环境变量中匹配
    print(os.getenv('MODEL_ADAPTER_WEBSERVER_PORT' , -1))
    MODEL_ADAPTER_WEBSERVER_PORT = os.getenv('MODEL_ADAPTER_WEBSERVER_PORT' , '18003')
    MODEL_ADAPTER_WEBSERVER_PORT = int(MODEL_ADAPTER_WEBSERVER_PORT)
    uvicorn.run("main:app",host="0.0.0.0",port=MODEL_ADAPTER_WEBSERVER_PORT,reload=False,log_level="info")

